﻿using System;

namespace BaseSyntax
{
    public class ValueConvertor:ITest
    {
        private void defaultConvert()
        {
            byte a = 1;
            short b = a;
            Console.WriteLine($"default convert: {b}");
        
            
            char c = 'c';
            ushort s = c;
            Console.WriteLine($"{s}");
        }

        private void explicitTest()
        {
            short a = 300;
            byte b = (byte)a;
            Console.WriteLine("explicit convert: {0}", b);
        }

        private void withOperator()
        {
            short a = 1;
            int b = 2;
            short c = 2;
            int d = a*c;// short*short => int
            Console.WriteLine("operator test: {0}", d);
            Console.WriteLine("operator test: {0}", (a*b).GetType());
        }

        private void ConvertTest()
        {
            int a = Convert.ToInt32("23123213");
            Console.WriteLine("convertTest: {0}", a);
            byte b = Convert.ToByte("121212");
            Console.WriteLine("convertTest: {0}", b);
        }
        
        

        private void ConvertError()
        {
            // 抛出异常
            Convert.ToInt32("dd");
        }

        private void BoolToString()
        {
            string s = true.ToString();
            
            Console.WriteLine(s);
        }

        public void ToBool()
        {
            // 最好不要使用此转换
            int a = -2;
            bool b = System.Convert.ToBoolean(a);
            Console.WriteLine(b);
        }
        
        public void Test()
        {
            // BoolToString();
            ToBool();
            // defaultConvert();
            // explicitTest();
            // withOperator();
            // ConvertTest();
        }
    }
}